﻿@page "/sdk/objects/page/r/{RecordId}/{PageName?}"
@using System.Web;
@using WebVella.TagHelpers.Models;
@model WebVella.Erp.Plugins.SDK.Pages.Page.DetailsModel
@using WebVella.Erp.Web.Utils;
@{
	Layout = "~/Pages/_AppMaster.cshtml";
	ViewData["Title"] = "Page details";
	var pageIconClass = "fa fa-file";
	if (!String.IsNullOrWhiteSpace(Model.ErpPage.IconClass)){
		pageIconClass = Model.ErpPage.IconClass;
	}
}

<wv-page-header color="#dc3545" area-label="Pages" title="@Model.ErpPage.Label" subtitle="Details"
	icon-class="@pageIconClass" return-url="@Model.ReturnUrl">

<wv-page-header-actions>
	<wv-button type='Submit' form="DeletePageForm" onclick='return confirm("Are you sure you want to delete the page?")' class='btn btn-white btn-sm'><i class='fa fa-trash-alt go-red'></i> Delete Page</wv-button>
	@if (!String.IsNullOrWhiteSpace(Model.PagePublicUrl))
	{
	<a href='@Model.PagePublicUrl' target="_blank" class='btn btn-white btn-sm'><i class='fas fa-external-link-alt'></i> Visit Page</a>
	}
	<wv-button type='Submit' form="ClonePageForm" onclick="return confirm('Are you sure you want to clone this page?')" class='btn btn-white btn-sm'><i class='fa fa-file go-gray'></i> Clone Page</wv-button>
	<a href='/sdk/objects/page/m/@(Model.ErpPage != null ? Model.ErpPage.Id : Guid.Empty)/manage?returnUrl=@Html.Raw(HttpUtility.UrlEncode(Model.CurrentUrl))' class='btn btn-white btn-sm'><i class='fa fa-cog go-orange'></i> Manage Details</a>
</wv-page-header-actions>

<wv-page-header-toolbar>
	@foreach (var action in Model.HeaderToolbar)
	{
		@Html.Raw(action)
	}
</wv-page-header-toolbar>

	</wv-page-header>

<wv-form label-mode="Stacked" mode="Display">
	<wv-section class="mt-4" title="General" is-card="true">
		<wv-row>
			<wv-column span="6">
				<wv-field-text label-text="Name" value="@Model.Name" name="Name" required="true"></wv-field-text>
			</wv-column>
			<wv-column span="6">
				<wv-field-text label-text="Label" value="@Model.Label" name="Label" required="true"></wv-field-text>
			</wv-column>
		</wv-row>
		<wv-row>
			<wv-column span="6">
				<wv-field-icon label-text="Icon CSS Class" value="@Model.IconClass" name="IconClass"></wv-field-icon>
			</wv-column>
			<wv-column span="6">
				<wv-field-number label-text="Weight" decimal-digits="0" value="@Model.Weight" name="Weight"></wv-field-number>
			</wv-column>
		</wv-row>
		<wv-row>
			<wv-column span="6">
				<wv-field-text label-text="Layout" value="@Model.Layout" name="Layout"></wv-field-text>
			</wv-column>
			<wv-column span="6">
				@if (Model.Access.Count > 0)
				{
					<wv-field-multiselect label-text="Access (inherited from application)" value="@Model.Access" name="Access" options="Model.RoleOptions.ToWvSelectOption()"></wv-field-multiselect>
				}
				else
				{
					<wv-field-plaintext label-text="Access (inherited from application)" value="@("<span class='go-gray'>no access restrictions</span>")"></wv-field-plaintext>
				}
			</wv-column>
		</wv-row>
		<wv-row>
			<wv-column>
				<wv-field-textarea label-text="Description" value="@Model.Description" name="Description"></wv-field-textarea>
			</wv-column>
		</wv-row>
	</wv-section>
	<wv-section class="mt-4" title="Sitemap" is-card="true">
		@await Component.InvokeAsync("WvSdkPageSitemap", new { pageId = Model.RecordId, mode = WvFieldRenderMode.Display})
	</wv-section>
</wv-form>

<wv-form name="DeletePageForm" id="DeletePageForm" action="/sdk/objects/page/r/@Model.ErpPage.Id/?op=delete"></wv-form>
<wv-form name="ClonePageForm" id="ClonePageForm" action="/sdk/objects/page/r/@Model.ErpPage.Id/?op=clone"></wv-form>